<template>
	<a-card :bordered="false" :body-style="{ 'padding-bottom': '0px' }" class="mb-2">
		<a-1 ref="formRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="标题" name="title">
						<a-input v-model:value="searchFormState.title" allow-clear></a-input>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-form-item label="积分类型" name="bonusType">
						<a-select
							v-model:value="searchFormState.bonusType"
							:options="bonusTypeOptions"
							placeholder="请选择积分类型"
							allow-clear
						></a-select>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" html-type="submit" @click="table.refresh()">查询</a-button>
					<a-button style="margin: 0 8px" @click="() => formRef.resetFields()">重置</a-button>
				</a-col>
			</a-row>
		</a-1>
	</a-card>
	<a-card :bordered="false">
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>
			<template #headerCell="{title, column}">
				<template v-if="title === '事件'">
					<div style="text-align: center">事件</div>
				</template>
			</template>
			<template #operator class="table-operator">
<!--				<a-space>-->
<!--					<a-button type="primary">-->
<!--						导出-->
<!--					</a-button>-->
<!--				</a-space>-->
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'bonusType'">
					{{ $TOOL.dictTypeData('BONUS_TYPE', record.bonusType + '') }}
				</template>
				<template v-if="column.dataIndex === 'status'">
					{{ record.status === 1 ? '启用' : '停用' }}
				</template>
				<template v-if="column.dataIndex === 'action'">
					<a-space>
						<a @click="form.onOpen(record)">编辑</a>
					</a-space>
				</template>
			</template>
		</s-table>
	</a-card>
	<Form ref="form" @successful="table.refresh(true)" />
</template>

<script setup name="crmBonusLog">
	import { message } from 'ant-design-vue'
	import crmApi from '@/api/crm/crmApi'
	import Form from './form.vue'
	import tool from '@/utils/tool'
	let searchFormState = reactive({})
	const formRef = ref()
	const table = ref(null)
	let form = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: true }
	const columns = [
		{
			title: '标题',
			dataIndex: 'title',
			width: 200
		},
		{
			title: '积分类型',
			dataIndex: 'bonusType',
			width: 80,
			align: 'center'
		},
		{
			title: '状态',
			dataIndex: 'status',
			width: 80,
			align: 'center'
		},
		{
			title: '开始时间',
			dataIndex: 'startTime',
			ellipsis: true,
			sorter: true,
			width: 160,
			align: 'center'
		},
		{
			title: '结束时间',
			dataIndex: 'endTime',
			ellipsis: true,
			sorter: true,
			width: 160,
			align: 'center'
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			width: 120
		}
	]
	let selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		alert: {
			show: false,
			clear: () => {
				selectedRowKeys = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	let bonusTypeOptions = tool
		.dictTypeList('BONUS_TYPE')
		.map((item) => {
			return {
				value: item['dictValue'],
				label: item['name']
			}
		})
	// 列表数据
	const loadData = (parameter) => {
		return crmApi.bonusRuleList(Object.assign(parameter, searchFormState)).then((res) => {
			return res
		})
	}
</script>

<style scoped>

</style>
